import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    component: HomeView,
    children:[
      {
        path: '/homeView',
        name: 'homeView',
        component: () => import('@/views/HomeView/index'),
        meta:{
          title:'首页',
        }
      },
      {
        path: '/portarit',
        name: 'portarit',
        component: () => import('@/views/users/portarit'),
        meta:{
          title:'个人信息',
        }
      },
      {
        path: '/administrators',
        name: 'administrators',
        component: () => import('@/views/HomeView/administrators'),
        meta:{
          title:'管理员配置',
        }
      },{
        path: '/userstrators',
        name: 'userstrators',
        component: () => import('@/views/HomeView/userstrators'),
        meta:{
          title:'用户管理',
        }
      },{
        path: '/management',
        name: 'management',
        component: () => import('@/views/HomeView/management'),
        meta:{
          title:'商品管理',
        }
      },{
        path: '/shopping',
        name: 'shopping',
        component: () => import('@/views/HomeView/shopping'),
        meta:{
          title:'订单管理',
        }
      },{
        path: '/bannner',
        name: 'bannner',
        component: () => import('@/views/HomeView/bannner'),
        meta:{
          title:'轮播图管理',
        }
      },{
        path: '/news',
        name: 'news',
        component: () => import('@/views/HomeView/news'),
        meta:{
          title:'新闻资讯',
        }
      },
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/login'),
    meta:{
      title:'登录页面',
    }
  },

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
const routerPush = VueRouter.prototype.push;
VueRouter.prototype.push = function (location) {
  return routerPush.call(this, location).catch((err) => {});
};
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = '博客家纺后台管理系统-'+to.meta.title;
  }else if (to.meta.title==null){
    document.title='博客家纺后台管理系统'
  }
  next();
});
export default router
